/* eslint-disable import/no-extraneous-dependencies */
import path from 'path';
import { defineConfig } from 'vite';
import dtsPlugin from 'vite-plugin-dts';
import eslintPlugin from 'vite-plugin-eslint';

export default defineConfig({
  plugins: [eslintPlugin(), dtsPlugin({
    outputDir: 'dist/types',
  })],
  build: {
    lib: {
      entry: path.resolve(__dirname, 'src/index.ts'),
      name: '_yu',
      fileName: (format) => `index.${format}.js`,
    },
    rollupOptions: {
      // 确保外部化处理那些你不想打包进库的依赖
      external: ['dayjs', 'lodash/fp', 'qs', 'number-precision'],
      // 在 UMD 构建模式下为这些外部化的依赖提供一个全局变量
      output: {
        globals: {
          dayjs: 'dayjs',
          'lodash/fp': 'fp',
          qs: 'Qs',
          'number-precision': 'NP',
        },
      },
    },
  },
});
